package com.union.core.action;

import java.util.List;
import java.util.Map;

import com.union.core.model.Param;
import com.union.core.service.ParamService;

public abstract class ParamAction extends BaseAction{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6588944348038694535L;

	private static Map<String, Object> paramMap;
	
	public Map<String, Object> getParamMap() {
		return paramMap;
	}
	
	public void setParamMap(Map<String, Object> paramMap1) {
		paramMap = paramMap1;
	}
	
	public static void setParamMap(){
		paramMap = ParamService.getInstance().getAllParamType();
	}
	
	public static Param getParam(String paramCode, String paramType){
		String newParamType = paramType;
		if(paramType != null && !paramType.startsWith("param")){
			newParamType = "param" + newParamType;
		}
		if(paramMap == null || paramMap.get(newParamType) == null){
			return null;
		}
		@SuppressWarnings("unchecked")
		List<Param> paramList = (List<Param>)paramMap.get(newParamType);
		for(Param param : paramList){
			if(param.getParamCode().equals(paramCode)){
				return param;
			}
		}
		return null;
	}
	
	public static String getParamName(String paramCode, String paramType){
		Param param = getParam(paramCode, paramType);
		if(param != null){
			return param.getParamName();
		}
		return "";
	}
	
	public static String getParamStr1(String paramCode, String paramType){
		Param param = getParam(paramCode, paramType);
		if(param != null){
			return param.getStr1();
		}
		return "";
	}
	
	static{
		setParamMap();
	}
}
